<?php

require_once dirname(__FILE__).'/../lib/sonyGeneratorConfiguration.class.php';
require_once dirname(__FILE__).'/../lib/sonyGeneratorHelper.class.php';

/**
 * sony actions.
 *
 * @package    astolfo
 * @subpackage sony
 * @author     Emerson Estrella
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class sonyActions extends autoSonyActions
{

	public function executeListAssets(sfWebRequest $request){
		//$this->redirect('@asset?section_id='.$request->getParameter('id'));
		//$this->forward('asset', 'index', array('section_id' => $request->getParameter('id')));
		$this->forward('sony_category_assets', 'index', array('category_id' => $request->getParameter('id'), 'category' => $this->getRoute()->getObject()));
	}
	
	public function executeAjaxupdate(sfWebRequest $request)
	{
		$this->setLayout(false);
	  $this->query = Doctrine_Query::create()
			->select('c.*')
			->from('SonyCategory c')
			->orderBy('c.display_order');
	  $this->pager = $this->getPager();
		$this->sort = $this->getSort();
	}
	
	protected function getPager()
	{
		$pager = $this->configuration->getPager('SonyCategory');
		$pager->setQuery($this->query);
		$pager->setPage($this->getPage());
		$pager->init();
		return $pager;
	}
	
	public function executeAjaxorder(sfWebRequest $request)
	{
		$order = 1;
		foreach($request->getParameter('listItem') as $i){
			$cat = Doctrine::getTable('SonyCategory')->find($i);
			if($cat){
				$cat->setDisplayOrder($order);
				$cat->save();
				$order++;
			}
		}
		die();
	}

	public function executeAjaxdelete(sfWebRequest $request)
	{
		$this->setLayout(false);
		$cat = Doctrine::getTable('SonyCategory')->find($request->getParameter('id'));
		if($cat)
			$cat->delete();
		die();
	}
	
	
}
